package com.luckmgr.service.impl;


import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.common.service.BaseService;
import com.luckmgr.dao.ActivityMapper;
import com.luckmgr.dao.UserMapper;
import com.luckmgr.entity.db.Activity;
import com.luckmgr.service.ActivityLevelService;
import com.luckmgr.service.ActivityService;
import com.luckmgr.service.LevelPrizeService;
import com.luckmgr.service.LuckUserService;
import com.luckmgr.service.PrizeService;


@Service
public class ActivityServiceImpl extends BaseService<Activity> implements ActivityService {

	

	@Autowired
	PrizeService prizeServiceImpl;
	
	@Autowired
	LuckUserService luckUserServiceImpl;
	
	@Autowired
	LevelPrizeService levelPrizeServiceImpl;
	
	@Autowired
	ActivityLevelService activityLevelServiceImpl;

	ActivityMapper activityMapper;
	
	@Resource(name="activityMapper")
    public void initCompanyMapper(ActivityMapper activityMapper) {
		this.activityMapper = activityMapper;
        super.setBaseDao(activityMapper);
    }
	
	
	@Override
	public int deleteActivity(Integer id) {
		luckUserServiceImpl.deleteByActivity(id);
		levelPrizeServiceImpl.deleteByActivity(id);
		activityLevelServiceImpl.deleteByActivity(id);
		prizeServiceImpl.deleteByActivity(id);
		activityMapper.deleteByPrimaryKey(id);
		return 0;
	}

	@Override
	public int updateStatus(Integer id, Integer status) {
		Activity activity = activityMapper.selectByPrimaryKey(id);
		if(null == activity)return 0;
		if(1==status){
			Activity validActivity = activityMapper.findValidActivity(id,activity.getSeriesCode());
			if(null != validActivity){
				return 2;
			}
			activityMapper.updateStatus(id,status);
		}else{
			activityMapper.updateStatus(id, status);
		}
		return 1;
	}

}